<?php

/**
 * Post class.
 * 
 * @extends AppModel
 */
class Post extends AppModel {

    /**
     * latest function.
     *
     * @access public
     * @return array
     */
    public function latest($limit = 1) {
        $posts = $this->find('all', array(
            'conditions' => array(
                'Post.is_published' => 1
            ),
            'order' => array(
                'Post.publish_date' => 'DESC',
                'Post.created' => 'DESC'
            ),
            'limit' => $limit
                ));
        if (count($posts) === 1 && $limit === 1) {
            $posts = $posts[0];
        }
        return $posts;
    }

    /**
     * recent function.
     * 
     * @access public
     * @return array
     */
    public function recent() {
        return $this->find('all', array(
                    'conditions' => array(
                        'Post.is_published' => 1
                    ),
                    'order' => array(
                        'Post.publish_date' => 'DESC'
                    ),
                    'limit' => 5
                ));
    }

}
